<?php

namespace Biz\pockets\callback;

use Doraemon\tools\Log;

trait resultCallBack
{
    private static function _resultCallBack($result, $params)
    {
        try {
            if(!class_exists($params['callback'])) {
                Log::error("回调失败: 类未找到", [
                    $params['sign'],
                    $params['content'],
                ]);
                return false;
            }
            $callbackResult = call_user_func_array([
                $params['callback'],
                $params['callback']::CALLBACK_METHOD
            ], [
                $params['sign'],
                $result
            ]);
            if ($callbackResult) {
                Log::debug("回调成功", [
                    $params['sign'],
                    $params['content'],
                    $result
                ]);
            } else {
                Log::error("回调失败", [
                    $params['sign'],
                    $params['content'],
                    $result
                ]);
            }
            return true;
        } catch (\Exception $e) {
            Log::error("回调失败", [
                $params['sign'],
                $params['content'],
                $result,
                $e
            ]);
            return false;
        }
    }
}

